package scanner.com.activity;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;

import scanner.com.scanner.R;

/**
 * Created by Administrator on 2016/7/15.
 */
public class Readnum extends AppCompatActivity {
    private  Context context;
    private EditText Phone,Name;
    private  String sr,sn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_encode);
        findView();
        insertContact(context,sr,sn);

    }
    private void findView(){
        Phone=(EditText) findViewById(R.id.contact_name1);
        Name=(EditText)findViewById(R.id.phone_num_list1);
        sn=Name.getText().toString();
        sr=Phone.getText().toString();
    }

    private Uri insertContact(Context context, String name, String phone) {
        this.context=context;
        ContentValues values = new ContentValues();
        values.put(Contacts.People.NAME, name);
        Uri uri = getContentResolver().insert(Contacts.People.CONTENT_URI, values);
        Uri numberUri = Uri.withAppendedPath(uri, Contacts.People.Phones.CONTENT_DIRECTORY);
        values.clear();

        values.put(Contacts.Phones.TYPE, Contacts.People.Phones.TYPE_MOBILE);
        values.put(Contacts.People.NUMBER, phone);
        getContentResolver().insert(numberUri, values);

        return uri;
    }


}
